package Offer.offer2016;


public class Test09 
{

	public static void main(String[] args) 
	{
		System.out.println(Fibonacci(30));
		System.out.println(Fibonacci.getFibonacci(30) );
	}
    public static int Fibonacci(int n)
    {
    	if(n==0)
    	{
    		return 0;
    	}
    	if(n==1)
    	{
    		return 1;
    	}
    	int fibonaccione=0;
    	int fibonaccitwo=1;
    	int fibonacci=0;
    	for(int i=2;i<=n;i++)
    	{
    		fibonacci= fibonaccione+fibonaccitwo;
    		fibonaccione=fibonaccitwo;
    		fibonaccitwo=fibonacci;    		
    	}
    	return fibonacci;    	
    }
}

class Fibonacci{
	public static int getFibonacci(int n){
		int one = 0;
		int two = 1;
		int fibN = 0;
		if(n == 0) return one;
		if(n == 1) return two;
		for(int i = 2; i <= n; i++){
			fibN = one + two;
			one = two;
			two = fibN;
		}
		return fibN ;
	}
}
